package com.cht.controller;

import com.cht.pojo.Article;
import com.cht.service.ArticleService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
public class ArticleController {

    @Autowired
    private ArticleService articleService;
    @RequestMapping("/login")
    public String toLoginPage(Model model){

        return "client/login";
    }

    @RequestMapping("/header")
    public String header(Model model){
        return "client/header";
    }

    @RequestMapping("/index")
    public String index(@RequestParam(value = "pageNum", defaultValue = "1")Integer pageNum, @RequestParam(value = "pageSize", defaultValue = "2") Integer pageSize, Model model){
        PageInfo<Article> pageInfo = articleService.findAll(pageNum,pageSize);
        List<Article> articles = pageInfo.getList();
        System.err.println("查询出结果数量:"+articles.size());
        model.addAttribute("articles",articles);

        model.addAttribute("pageInfo", pageInfo);
        return "client/index";
    }
}
